package com.example.demo.service.impl;

import com.example.demo.common.ResponseMessage;
import com.example.demo.dao.AddressMapper;
import com.example.demo.pojo.Address;
import com.example.demo.service.IAddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("iAddressService")
public class AddressServiceImpl implements IAddressService {
    @Autowired
    private AddressMapper addressMapper;

    @Override
    public int addAddress(Address address) {
        return addressMapper.insert(address);
    }

    @Override
    public int deleteAddress(Integer id) {
        return addressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateAddress(Address address) {
        return addressMapper.updateByPrimaryKeySelective(address);
    }

    @Override
    public Address selectAddress(Integer id) {
        return addressMapper.selectByPrimaryKey(id);
    }

    @Override
    public ResponseMessage getAddressList(int nowPage, int pageSize) {
        PageHelper.startPage(nowPage,pageSize);
        List<Address> addressList = addressMapper.selectAll();
        PageInfo pageInfo = new PageInfo(addressList);
        return ResponseMessage.createSuccessMessage(pageInfo);
    }


}
